﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Main.Master" AutoEventWireup="true" CodeBehind="SearchResult.aspx.cs" Inherits="Linkmeme.Views.User.SearchResult" %>
<%@ Import Namespace="Linkmeme" %>
<%@ Import Namespace="Linkmeme.Controllers" %>
<%@ Import Namespace="Linkmeme.Models" %>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">
<ul>
<%foreach (User u in this.ViewData)
  {
      %><li>
        <span><%= u.UserName %></span> &nbsp;   
        <%= IsFriend(u) ? "好友 - (" + Html.ActionLink<UserController>(uc => uc.RemoveFriend(u.UserId), "删除好友", new { id = "remove" + u.UserName }) + ")" : Html.ActionLink<UserController>(uc => uc.AddFriend(u.UserId), "加为好友", new { id="add" + u.UserName})%>
        </li>
      <%
  } %>
  </ul>
  <span style="display:none; " id="controlBar">
  <a href="#" id="addFriendButton" > +++ </a>
  </span>
  
  <script language="javascript">
    
    $(document).ready(function() {
        $("li a[id^=add]").click(function()
        {
          //  $(this).attr("enabled", "false");
            $.getJSON($(this).attr("href"), 
                    function(result)
                    {
                        if (result.isSuccessful == false)
                        {
                            //alert(result.errorMessage);
                            alert("请先登录");
                        }
                        else 
                        {
                            alert("添加好友成功");
                            window.location.reload();
                        }
                            
                    }
            );
            return false;
        });
        
        $("li a[id^=remove]").click(function()
        {
            $.getJSON($(this).attr("href"), 
                    function(result)
                    {
                        if (result.isSuccessful == false)
                        {
                            //alert(result.errorMessage);
                            alert("无法删除");
                        }
                        else 
                        {
                            alert("已删除好友");
                            window.location.reload();
                        }
                    }
            );
            return false;
        });
        
        
//        $("li span").mouseover(function(e)
//            {
//                $("#controlBar").show("slow");
//            }
//        ).mouseout(function(e));
    });
</script>
</asp:Content>

